package cpr.helper;

import java.util.StringTokenizer;

import cpr.data.HLVector;

public class ScoreHelper {
    
	 public static int[] firstSetScoreOf(HLVector vec) {
	    	int[] result = new int[2];
	    	for (int i = 0; i < vec.values.length; i++) {
				if (vec.values[i]!=0) {
					result[0] = i;
					result[1] = vec.values[i];
				}
			} 
	    	return result;
	    }
    public static String printHLVectorAsArray(HLVector vec) {
    	return printHLVectorAsArray(vec, ",");
    }
    
    public static String printHLVectorAsArray(HLVector vec, String delim) {
    	StringBuffer sb = new StringBuffer();
    	for (int i = 0; i < vec.values.length; i++) {
			sb .append(vec.values[i]);
			if (i < vec.values.length-1) {
				sb.append(delim);
			}
		}
    	return sb.toString();
    }
	public static int convertStringToScore(String str) {
		int IMAGE_SCORE = -1;
		String sep = ",-";
		
		
		StringTokenizer st = new StringTokenizer(str,sep);
        if (st.countTokens()==5) {
            int[] dec = new int[5];
            for (int i = 0; i < dec.length; i++) {
                String s = st.nextToken();
                dec[i] = Integer.parseInt(s);
            }
            HLVector vec = new HLVector(dec);
            IMAGE_SCORE = vec.score;
        } else if (st.countTokens()==1) {
            IMAGE_SCORE = Integer.parseInt(str);
        } else {
        	throw new RuntimeException("can not parse score: "+str);
        }
        return IMAGE_SCORE;
	}
}
